//
//  UIBarButtonItem+extension.swift
//  SwiftProject
//
//  Created by Lausen on 2017/7/12.
//  Copyright © 2017年 id. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    
    /// 自定义BarButtonItem
    ///
    /// - Parameters:
    ///   - title: item的标题
    ///   - font: item的字体大小
    ///   - target: 监听者
    ///   - action: 执行时间
    ///   - isBack: 是否是返回的按钮
    convenience init(title: String,font: CGFloat = 16,target: Any?,action: Selector, isBack: Bool = false){
        
        let btn:UIButton = UIButton.cz_textButton(title, fontSize: 16, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        if isBack {
            
            let imageName = "navigationbar_back_withtext"
            
            btn.setImage(UIImage(named: imageName), for: .normal)
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
        }
        
        ///重新自适应一下图片和字体的大小
        btn.sizeToFit()
        
        ///调用self.init实例化
        self.init(customView: btn)
    }
}
